package component.controls.ui
{
	import component.controls.Button;
	import component.controls.interfaces.IListCell;
	import component.controls.interfaces.IListCellData;
	import component.global.ComponentSetting;
	import component.global.utils.ObjectUtil;
	
	import flash.display.DisplayObject;
	import flash.events.MouseEvent;
	
	public class ListCell extends Button implements IListCell
	{
		public function ListCell($label:String = ComponentSetting.BUTTON_DEFAULT_LABEL,$width:int = ComponentSetting.BUTTON_DEFAULT_WIDTH,  $height:int = ComponentSetting.BUTTON_DEFAULT_HEIGHT)
		{
			super($label,$width,$height);
		}
		
		protected var _data:IListCellData;
		protected var _selected:Boolean;
		
		override protected function init():void{
			super.init();
		}
		
		public function set scrollMode(value:Boolean):void
		{
		}
		
		public function set data(value:IListCellData):void
		{
			if(value == _data)return;
			_data = value;
			label = _data.label;
		}
		
		public function get data():IListCellData
		{
			return _data.data;
		}
		
		public function get selected():Boolean{
			return _selected;
		}
		
		public function set selected(value:Boolean):void{
			if(_selected == value)return;
			_selected = value;
			if(_selected){
				_background.filters = _filters[2];
			} else {
				_background.filters = _filters[0];
			}
		}
		
		override protected function __onMouseEventHandler(e:MouseEvent):void{
			switch(e.type){
				case MouseEvent.ROLL_OVER:
					if(_selected){
						_background.filters = _filters[2]
					} else {
						_background.filters = _filters[1];
					}
					break;
				case MouseEvent.MOUSE_UP:
					_background.filters = _filters[1];
					break;
				case MouseEvent.ROLL_OUT:
					if(_selected){
						_background.filters = _filters[2]
					} else {
						_background.filters = _filters[0];
					}
					break;
				case MouseEvent.MOUSE_DOWN:
					_background.filters = _filters[2];
					break;
			}
		}
		
		override public function get asDisplayObject():DisplayObject{
			return this as DisplayObject;
		}
		
		override public function dispose():void{
			super.dispose();
			ObjectUtil.dispose(_data);
		}
	}
}